<?php

/**
 * @Author: wuchenge
 * @Date:   2022-04-20 10:58:37
 * @Email: ligui0506@126.com
 * @Descript:
 */
namespace App\Requests;

use Illuminate\Http\Request;

class LabelRequest extends FormRequest
{
    public function rules(Request $request)
    {
        $params = $request->input();
        $id     = 0;
        if (array_key_exists('id', $params)) {
            $id = $params['id'];
        }
        return [
            'title'  => [
                'required',
                'unique:labels,title,' . $id,
            ],
            'img'    => [
                'required',
            ],
            'status' => [
                'required',
                'in:1,2',
            ],
            'id'     => [
                'required',
                'integer',
                'gt:0',
            ],

        ];
    }

    public function messages()
    {
        return [
            'title.required'  => '100301',
            'title.unique'    => '100302',
            'img.required'    => '100303',
            'status.required' => '100305',
            'status.in'       => '100306',
            'id.required'     => '100307',
            'id.integer'      => '100308',
            'id.gt'           => '100309',
        ];
    }

    public $scene = [
        'admin.label.add'    => ['title', 'img', 'status'],
        'admin.label.modify' => ['title', 'img', 'status', 'id'],
    ];
}
